<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>DB-&gt;put</title>
    <link rel="stylesheet" href="gettingStarted.css" type="text/css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" />
    <link rel="start" href="index.html" title="Berkeley DB Upgrade Guide" />
    <link rel="up" href="upgrade_3_1_toc.html" title="Chapter 13. Upgrading Berkeley DB 3.0 applications to Berkeley DB 3.1" />
    <link rel="prev" href="upgrade_3_1_set_paniccall.html" title="DB_ENV-&gt;set_paniccall, DB-&gt;set_paniccall" />
    <link rel="next" href="upgrade_3_1_dup.html" title="identical duplicate data items" />
  </head>
  <body>
    <div xmlns="" class="navheader">
      <div class="libver">
        <p>Library Version 12.1.6.2</p>
      </div>
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">DB-&gt;put</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="upgrade_3_1_set_paniccall.html">Prev</a> </td>
          <th width="60%" align="center">Chapter 13. Upgrading Berkeley DB 3.0 applications to Berkeley DB 3.1</th>
          <td width="20%" align="right"> <a accesskey="n" href="upgrade_3_1_dup.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="sect1" lang="en" xml:lang="en">
      <div class="titlepage">
        <div>
          <div>
            <h2 class="title" style="clear: both"><a id="upgrade_3_1_put"></a>DB-&gt;put</h2>
          </div>
        </div>
      </div>
      <p>For the Queue and Recno access methods, when the <a href="../api_reference/C/dbput.html#dbput_DB_APPEND" class="olink">DB_APPEND</a> flag
is specified to the <a href="../api_reference/C/dbput.html" class="olink">DB-&gt;put()</a> method, the allocated record number is
returned to the application in the <span class="bold"><strong>key</strong></span> <a href="../api_reference/C/dbt.html" class="olink">DBT</a> argument.  In
previous releases of Berkeley DB, this <a href="../api_reference/C/dbt.html" class="olink">DBT</a> structure did not follow
the usual <a href="../api_reference/C/dbt.html" class="olink">DBT</a> conventions.  For example, it was not possible to
cause Berkeley DB to allocate space for the returned record number.  Rather,
it was always assumed that the <span class="bold"><strong>data</strong></span> field of the <span class="bold"><strong>key</strong></span>
structure referred to memory that could be used as storage for a
db_recno_t type.</p>
      <p>As of the Berkeley DB 3.1.0 release, the <span class="bold"><strong>key</strong></span> structure behaves as
described in the <a href="../api_reference/C/dbt.html" class="olink">DBT</a> C++/Java class or C structure documentation.</p>
      <p>Applications which are using the <a href="../api_reference/C/dbput.html#dbput_DB_APPEND" class="olink">DB_APPEND</a> flag for Queue and
Recno access method databases will require a change to upgrade to the
Berkeley DB 3.1 releases.  The simplest change is likely to be to add the
<a href="../api_reference/C/dbt.html#dbt_DB_DBT_USERMEM" class="olink">DB_DBT_USERMEM</a> flag to the <span class="bold"><strong>key</strong></span> structure.  For example,
code that appears as follows:</p>
      <pre class="programlisting">DBT key;
db_recno_t recno;

memset(&amp;key, 0, sizeof(DBT));
key.data = &amp;recno;
key.size = sizeof(recno);
DB-&gt;put(DB, NULL, &amp;key, &amp;data, DB_APPEND);
printf("new record number is %lu\n", (u_long)recno);</pre>
      <p>would be changed to:</p>
      <pre class="programlisting">DBT key;
db_recno_t recno;

memset(&amp;key, 0, sizeof(DBT));
key.data = &amp;recno;
key.ulen = sizeof(recno);
key.flags = DB_DBT_USERMEM;
DB-&gt;put(DB, NULL, &amp;key, &amp;data, DB_APPEND);
printf("new record number is %lu\n", (u_long)recno);</pre>
      <p>Note that the <span class="bold"><strong>ulen</strong></span> field is now set as well as the flag value.
An alternative change would be:</p>
      <pre class="programlisting">DBT key;
db_recno_t recno;

memset(&amp;key, 0, sizeof(DBT));
DB-&gt;put(DB, NULL, &amp;key, &amp;data, DB_APPEND);
recno = *(db_recno_t *)key-&gt;data;
printf("new record number is %lu\n", (u_long)recno);</pre>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="upgrade_3_1_set_paniccall.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="upgrade_3_1_toc.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="upgrade_3_1_dup.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">DB_ENV-&gt;set_paniccall, DB-&gt;set_paniccall </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> identical duplicate data items</td>
        </tr>
      </table>
    </div>
  </body>
</html>
